﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

using Willson.JsbManager.Entity;
using Willson.JsbManager.Idal;
using Willson.JsbManager.Comm;

namespace Willson.JsbManager.Dal
{
    public class DAL_table_xt_company : BaseDal<TableXtCompanyEntity>, ITableXtCompany
    {
        #region 对象实例及构造函数

		public static DAL_table_xt_company Instance
		{
			get
			{
				return new DAL_table_xt_company();
			}
		}
        public DAL_table_xt_company(): base("table_xt_company", "id", "company_order", true)
		{ }

        #endregion

        /// <summary>
        /// 将DataReader的属性值转化为实体类的属性值，返回实体类
        /// </summary>
        /// <param name="dr">有效的DataReader对象</param>
        /// <returns>实体类对象</returns>
        protected override TableXtCompanyEntity DataReaderToEntity(IDataReader dataReader)
        {
            TableXtCompanyEntity entity = new TableXtCompanyEntity();
            SmartDataReader reader = new SmartDataReader(dataReader);

            entity.Id = reader.GetInt32("id");
            entity.Pym = reader.GetString("pym");
            entity.Name = reader.GetString("name");
            entity.Address = reader.GetString("address");
            entity.Telphone = reader.GetString("telphone");
            entity.Gm = reader.GetInt32("gm");
            entity.Code = reader.GetString("code");
            entity.Memo = reader.GetString("memo");
            entity.Remove = reader.GetInt32("remove");
            entity.Company_order = reader.GetInt32("company_order");
            entity.Sjr = reader.GetString("sjr");

            return entity;
        }


        /// <summary>
        /// 将实体对象的属性值转化为Hashtable对应的键值(用于插入或者更新操作)
        /// (提供了默认的反射机制获取信息，为了提高性能，建议重写该函数)
        /// </summary>
        /// <param name="obj">有效的实体对象</param>
        /// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(TableXtCompanyEntity obj)
        {
            TableXtCompanyEntity info = obj as TableXtCompanyEntity;
            Hashtable hash = new Hashtable();

            hash.Add("id", info.Id);
            hash.Add("pym", info.Pym);
            hash.Add("name", info.Name);
            hash.Add("address", info.Address);
            hash.Add("telphone", info.Telphone);
            hash.Add("gm", info.Gm);
            hash.Add("code", info.Code);
            hash.Add("memo", info.Memo);
            hash.Add("remove", info.Remove);
            hash.Add("company_order", info.Company_order);
            hash.Add("sjr", info.Sjr);

            return hash;
        }

        //#region 接口重写
        ///// <summary>
        ///// 根据条件查询数据库,并返回对象集合
        ///// </summary>
        ///// <param name="recordTable">查询的条件</param>
        ///// <param name="isSort">是否排序</param>
        ///// <param name="op">操作方式</param>
        ///// <returns>指定对象的集合</returns>
        //public override List<Table_xt_company_entity> Find(Hashtable recordTable, SqlOperator op, bool isSort)
        //{
        //    SqlParameter[] param = new SqlParameter[recordTable.Count];
        //    IEnumerator eKeys = recordTable.Keys.GetEnumerator();

        //    StringBuilder tmp_where = new StringBuilder(null);
        //    string where = string.Empty;
        //    string order = string.Empty;
        //    string sql = string.Empty;

        //    int index = 0;

        //    while (eKeys.MoveNext())
        //    {
        //        string field = eKeys.Current.ToString();

        //        if (op == SqlOperator.And)
        //        {
        //            tmp_where.Append(string.Format(" {0} = @{1} and", field, field));
        //        }
        //        else if (op == SqlOperator.Like)
        //        {
        //            tmp_where.Append(string.Format(" {0} like '%'+@{1}+'%' and", field, field));
        //        }

        //        string val = recordTable[eKeys.Current.ToString()].ToString();
        //        param[index] = new SqlParameter(string.Format("@{0}", field), val);

        //        index++;

        //    }

        //    where = tmp_where.ToString() + " remove = 0";

        //    if (isSort)
        //    {
        //        if (sortField != string.Empty)
        //        {
        //            order = string.Format(" order by {0} {1}", sortField, isDescending ? "ASC" : "DESC");
        //        }
        //    }

        //    sql = string.Format("select {0} from {1} where {2} {3}", selectedFields, tableName, where, order);

        //    return GetList(sql, param);

        //}

        //#endregion
    }
}
